package cn.xxstudy.visitshop.ui.activity.login.viewmodel

import android.os.Looper
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import cn.xxstudy.visitshop.network.data.Response
import cn.xxstudy.visitshop.ui.activity.login.model.LoginData
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * @author ：DELL on 2021/3/23 .
 * @packages ：cn.xxstudy.visitshop.ui.activity.login.viewmodel .
 * TODO:登录ViewModel
 */
class LoginViewModel : ViewModel() {
    val loginSuccess = MutableLiveData<LoginData>()

    val loginFail = MutableLiveData<String>()

    fun login(nickName: String, password: String) {
        viewModelScope.launch {
//            LoginRepository().login(nickName, password, loginSuccess, loginFail)
            val request = LoginRepository().login2(nickName, password)
            if (request is Response.SUCCESS) {
                loginSuccess.value = request.data
            }
            if (request is Response.FAILED) {
                loginFail.postValue(request.message)
            }
        }
    }
}